package com.jkc.xh.adapters.viewholder;

import android.content.Context;
import android.text.Editable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jkc.xh.R;
import com.jkc.xh.models.HaltSellModel;

import org.androidannotations.annotations.AfterTextChange;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * Created by wangjie28 on 2015/11/13.
 */
@EViewGroup(R.layout.item_halt_sell)
public class HaltSellItemView extends RelativeLayout {

    @ViewById(R.id.optionLayout)
    View optionLayout;
    @ViewById(R.id.dataLayout)
    View dataLayout;
    @ViewById
    TextView stock_name;
    @ViewById
    TextView stock_code;
    @ViewById
    TextView sell_price;
    @ViewById
    TextView cansell_amount;
    @ViewById
    TextView rate_bal;
    @ViewById
    EditText inputBuyCnt;

    private long buyNum = 100;
    private HaltSellModel model;


    public HaltSellItemView(Context context) {
        super(context);
    }

    public HaltSellItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    public void bind(HaltSellModel model) {
        this.model = model;
        stock_name.setText(model.stock_name);
        stock_code.setText(model.stock_code);
        sell_price.setText(model.sell_price);
        cansell_amount.setText(model.cansell_amount);
        rate_bal.setText(model.getBalMoney(buyNum));
        inputBuyCnt.setText(buyNum + "");


//        if (model.isProfit()) {
//            setAllTextColor(getResources().getColor(R.color.text_color_red));
//        } else {
//            setAllTextColor(getResources().getColor(R.color.text_color_blue));
//        }
//        if (model.isStop()) {
//            setAllTextColor(getResources().getColor(R.color.text_color_gray));
//        }
    }

    @AfterTextChange(R.id.inputBuyCnt)
    void inputNumChange(TextView tv, Editable text) {
        checkInput();
    }

    void checkInput() {
        String inputStr = inputBuyCnt.getText().toString();
        if (TextUtils.isEmpty(inputStr)) {
            inputStr = "0";
        }
        long nowCount = Long.valueOf(inputStr);
        buyNum = nowCount;
        rate_bal.setText(model.getBalMoney(buyNum));
//        inputBuyCnt.setText(buyNum + "");
//        inputBuyCnt.setSelection(inputBuyCnt.getText().length());
    }


    public void showMoreOption() {
        optionLayout.setVisibility(View.VISIBLE);
    }

    public void disableMoreOption() {
        optionLayout.setVisibility(View.GONE);
//        dataLayout.setBackgroundColor(R.color);
    }

    private void setAllTextColor(int textColorId) {
        stock_name.setTextColor(textColorId);
//        own_amount.setTextColor(textColorId);
//        enable_amount.setTextColor(textColorId);
//        last_price.setTextColor(textColorId);
//        market_value.setTextColor(textColorId);
//        profit_money.setTextColor(textColorId);
//        profit_rate.setTextColor(textColorId);
//        stop_price.setTextColor(textColorId);
    }

}
